﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using static WXTest2.Controllers.ServiceController;

namespace WXTest2
{
    /// <summary>
    /// AccessToken 维护封装
    /// </summary>
    public class AccessToken_Helper
    {
        public static string access_token = null;

        public static string token = "servicewx";
        public static string AppID = "wx9bd3b4a8e08f5d7f";
        public static string AppSecret = "281d94883c849cc0fa7574174a4300aa";

        //public static void ExecGetAccess_Token()
        //{
        //    //启动前程处理
        //    if (access_token == null)
        //    {
        //        Task.Factory.StartNew(() =>
        //        {
        //            GetAccess_Token();
        //            Thread.Sleep(200000);
        //        });
        //    }
        //}
        ////定时获取access_token
        //private static void GetAccess_Token()
        //{

        //    var url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", AppID, AppSecret);
        //    //{ "access_token":"ACCESS_TOKEN","expires_in":7200}
        //    string result = NetHelper.Get(url);
        //    if (string.IsNullOrEmpty(result))
        //    {
        //        _log.WriteLine("GetAccess_Token，请求结果为空");
        //    }
        //    Access_TokenData resultData = result.JsonDeserialezer<Access_TokenData>();
        //    if (string.IsNullOrEmpty(resultData.access_token))
        //    {
        //        _log.WriteLine("获取失败：" + result);
        //    }
        //    else
        //    {
        //        access_token = resultData.access_token;
        //        _log.WriteLine("获取成功：" + access_token);
        //    }
        //}
    }
}